package com.uniledger.exchange.contact;

import android.arch.persistence.room.Ignore;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import com.uniledger.exchange.bank.BankCard;

import me.yokeyword.indexablerv.IndexableEntity;

/**
 * 用户对象模型
 */
public class UniContact implements IndexableEntity, Parcelable {

    public String id;

    @SerializedName("name")
    public String nick;
    public String lastName;
    public String firstName;

    @SerializedName("logo")
    public String avatar;//用户头像
    public String mobile;

    public String email;
    public String birth;
    public String pinyin;

    @SerializedName("bankcard")
    public BankCard bankCard;
    @SerializedName("stellar_addr")
    public String accountId;

    @Ignore
    public String amount;

    public String getAvatar() {
        if (TextUtils.isEmpty(avatar)){
            return "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1581886231,2344461411&fm=26&gp=0.jpg";
        }
        return avatar;
    }

    public UniContact() {
        this.avatar="https://timgsa.baidu.com/timg?" +
                "image&quality=80&size=b9999_10000&sec=1537949859190&di=712554c3de31273dab678b8751e57131&imgtype=0&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01e0e457b32f640000018c1b402bf2.png%401280w_1l_2o_100sh.png";
    }

    public UniContact(String nick, String mobile) {
        this.nick = nick;
        this.mobile = mobile;
    }

    @Override
    public String getFieldIndexBy() {
        return nick;
    }

    @Override
    public void setFieldIndexBy(String indexField) {
        this.nick = indexField;
    }

    @Override
    public void setFieldPinyinIndexBy(String pinyin) {
        this.pinyin = pinyin;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.id);
        dest.writeString(this.nick);
        dest.writeString(this.lastName);
        dest.writeString(this.firstName);
        dest.writeString(this.avatar);
        dest.writeString(this.mobile);
        dest.writeString(this.email);
        dest.writeString(this.birth);
        dest.writeString(this.pinyin);
        dest.writeParcelable(this.bankCard, flags);
        dest.writeString(this.accountId);
        dest.writeString(this.amount);
    }

    protected UniContact(Parcel in) {
        this.id = in.readString();
        this.nick = in.readString();
        this.lastName = in.readString();
        this.firstName = in.readString();
        this.avatar = in.readString();
        this.mobile = in.readString();
        this.email = in.readString();
        this.birth = in.readString();
        this.pinyin = in.readString();
        this.bankCard = in.readParcelable(BankCard.class.getClassLoader());
        this.accountId = in.readString();
        this.amount = in.readString();
    }

    public static final Creator<UniContact> CREATOR = new Creator<UniContact>() {
        @Override
        public UniContact createFromParcel(Parcel source) {
            return new UniContact(source);
        }

        @Override
        public UniContact[] newArray(int size) {
            return new UniContact[size];
        }
    };
}
